<?php

namespace app\index\controller;

use think\Controller;

class Index extends GetSlides
{

    public function cdx()
    {
        $this->redirect('/');   //重定向

    }

    public function _empty()
    {
        $this->redirect('/');   //空操作 解决用户恶意的输入 报错影响交互
    }

    public function index()
    {
        $this->get_slider();//返回banner
        $cates = [
            'xwzx' => ['id' => 'e3f73acd-31ca-4e24-8f8d-d5fb2f0af0cb', 'page_limit' => 3, 'type' => 'article'],//新闻资讯
            'yygg' => ['id' => 'de856513-de48-4034-88d2-e87b6b0b32ad', 'page_limit' => 5, 'type' => 'article'],//医院公告
            'mtbd' => ['id' => '6c384bdb-169b-450d-8851-28e7bceb6939', 'page_limit' => 3, 'type' => 'article'],//媒体报道
            'yzjz' => ['id' => '5587edf0-4481-4cda-8b3d-0c09a6bf0601', 'page_limit' => 2, 'type' => 'article'],//义诊与讲座
            //['id' => 'ab222f34-7a08-4b65-b6f3-03cb0e4cb9d8', 'page_limit' => 10, 'type' => 'article'],//健康教育
            'jkjy' => ['id' => '50982d10-7187-443b-a464-ae3998e55ff1', 'page_limit' => 10, 'type' => 'article'],//健康教育
            'jcsp' => ['id' => '4e19cb94-be56-4d4f-95c4-dc73f6eb53e1', 'page_limit' => 5, 'type' => 'article'],//精彩视频
            'dsj' => ['id' => '7e29a19b-0aa4-41f6-843f-b51d8e6aed48', 'page_limit' => 1000, 'type' => 'article'],//大事记
//            ['id' => 'ffef06e1-6745-4bbf-a35c-052252809ae7', 'page_limit' => 10, 'type' => 'article'],//专题活动
//            ['id' => '', 'page_limit' => 3, 'type' => 'departments'],
        ];
        $department_home = [
            'zlzx' => ['id' => '2728580c-06fc-4169-ad43-9ec1408f99f0', 'type' => 'department'],//诊疗中心
            'fssks' => ['id' => 'f7d007e6-401d-45c5-9919-72f12b94ca6d', 'type' => 'department'],//非手术科室
            'ssks' => ['id' => '5884bf44-192c-4113-9a59-1c840601f55b', 'type' => 'department'],//手术科室
            'ptks' => ['id' => '693e9cc3-7ff6-43b5-a376-795a590ddf5a', 'type' => 'department'],//平台科室
        ];
        $A = new Api();

        $data = [];
        $j = 0;
        $n = 0;
        $department = [];
        $department2 = [];
        $_departments = $A->get_menu('departments');
        $_departments = getImg($_departments);

        card_info_special_page($A, $cates, $data);
        foreach ($department_home as $key => $value) {
            $_data = $_departments;
            for ($i = 0; $i < count($_data['data']); $i++) {
                if ($_data['data'][$i]['relationships']['parent']['data']) {
                    if ($_data['data'][$i]['relationships']['parent']['data'][0]['id'] == $value['id']) {
                        $department2[$n] = [
                            'id' => $_data['data'][$i]['id'],
                            'name' => $_data['data'][$i]['attributes']['name'],
                            'brief' => strip_tags($_data['data'][$i]['attributes']['description']['value']),
                            'img' => $_data['data'][$i]['attributes']['imageurl']
                        ];
                        $n++;
                    }
                }
            }
            $n = 0;
            $key = 'department' . ($j + 1);
            $j++;
            $data[$key] = [
                'id' => $value['id'],
                'list' => $department2,
            ];
        }

        $GLOBALS['dar1'] = 'home';
        $this->assign($data);
        //获取医生
        $doctors = $A->get_index_doctors_list('1', 1);
        $doctors = getImg($doctors);
        $this->assign("doctors", $doctors['data']);
        $this->assign("department", $department);
        //获取科室
        $this->assign("web_title", "首页");
        return view();

    }

    public function building()
    {
        return view();
    }
}
